public class Demo2 {
    private static Object lockerA=new Object();
    private static Object lockerB=new Object();

    public static void main(String[] args) {
        Thread t1=new Thread(()->{
            synchronized (lockerA){
                System.out.println("t1加锁A完成");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            synchronized (lockerB){
                System.out.println("线程t1对B加锁");
            }
            }
        });
        Thread t2=new Thread(()->{
        synchronized (lockerB){
            System.out.println("t2加锁B完成");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (lockerA){
                System.out.println("线程t2对A加锁");
            }
        }
        });
        t1.start();
        t2.start();
    }
}
